//package cn.nexd.location.core;
//
//import org.json.JSONException;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 楼层检测
// * Created by admin on 15/9/23.
// */
//class NexdIndoorFloorDetection {
//    private Map<String, Double[]> mean = new HashMap<>();
//    private Map<String, Double[]> var = new HashMap<>();
//    private Map<String, Double[]> weight = new HashMap<>();
//    public String[] wifilist;
//
//
//    public String floorDetection(String wifi, NexdIndoorWifiExtractor cw) throws JSONException {
//        Double[] vec = cw.extractWifiWithRef(wifi, wifilist);
//        Double prob_max = -10000.0;
//        String floor = "-1";
//        for (String flr : mean.keySet()) {
//            Double prob = getFloorProbability(vec, flr);
//            if (prob > prob_max) {
//                prob_max = prob;
//                floor = flr;
//            }
//        }
//
//        return floor;
//    }
//
//    private Double getFloorProbability(Double[] vec, String key) {
//        Double sum = 0.0;
//        Double[] t_mean = mean.get(key);
//        Double[] t_var = var.get(key);
//        Double[] t_weight = weight.get(key);
//        for (int i = 0, len = vec.length; i < len; i++) {
//            if (vec[i] > 1e-3) {
//                sum += Math.exp(-Math.pow(vec[i] - t_mean[i], 2) / 2.0 / t_var[i] / t_var[i]) / t_var[i] * t_weight[i];
//            }
//        }
//        return sum;
//    }
//
//
//    public void loadConfiguration(final InputStream mean, final InputStream var, final InputStream weight, final InputStream wifilist) throws IOException {
//        //        ThreadPoolDelegate.getThreadPoolDelegate().getThreadPoolManager().addTask(new LoadFloorDetectionConfigThread(mean, var, weight, wifilist));
//        _loadMean(mean);
//        _loadVar(var);
//        _loadWeight(weight);
//        _loadWifilist(wifilist);
//    }
//
//
//    private void _loadWifilist(InputStream inputStream) throws IOException {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        try {
//            String line = bufferedReader.readLine();
//            if (line != null) {
//                wifilist = line.split(",");
//            }
//        } finally {
//            bufferedReader.close();
//        }
//    }
//
//    private void _loadMean(InputStream inputStream) throws IOException {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        try {
//            String line = bufferedReader.readLine();
//
//            while (line != null) {
//                String[] linesplit = line.split(":");
//                String[] value = linesplit[1].split(",");
//                Double[] digitValue = new Double[value.length];
//                for (int i = 0; i < value.length; i++) {
//                    digitValue[i] = Double.parseDouble(value[i]);
//                }
//                mean.put(linesplit[0], digitValue);
//                line = bufferedReader.readLine();
//            }
//        } finally {
//            bufferedReader.close();
//        }
//    }
//
//    private void _loadVar(InputStream inputStream) throws IOException {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        try {
//            String line = bufferedReader.readLine();
//
//            while (line != null) {
//                String[] linesplit = line.split(":");
//                String[] value = linesplit[1].split(",");
//                Double[] digitValue = new Double[value.length];
//                for (int i = 0; i < value.length; i++) {
//                    digitValue[i] = Double.parseDouble(value[i]);
//                }
//                var.put(linesplit[0], digitValue);
//                line = bufferedReader.readLine();
//            }
//        } finally {
//            bufferedReader.close();
//        }
//    }
//
//
//    private void _loadWeight(InputStream inputStream) throws IOException {
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        try {
//            String line = bufferedReader.readLine();
//
//            while (line != null) {
//                String[] linesplit = line.split(":");
//                String[] value = linesplit[1].split(",");
//                Double[] digitValue = new Double[value.length];
//                for (int i = 0; i < value.length; i++) {
//                    digitValue[i] = Double.parseDouble(value[i]);
//                }
//                weight.put(linesplit[0], digitValue);
//                line = bufferedReader.readLine();
//            }
//        } finally {
//            bufferedReader.close();
//        }
//    }
//}
